<?php include $this->admin_tpl('header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/haidaoblue/easyui.css">
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/icon.css">
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/hd_default_config.js"></script>
<script type="text/javascript" src="/template/default/statics/js/area.js"></script>
<script>var ajaxurl = "/index.php?m=admin&c=union&a=getArea";</script>
<div class="content" >
<div class="site">
	<?php echo C('site_name')?> <a href="#">联盟商家</a> > 联盟商家列表
</div>
<span class="line_white"></span>
<div class="install mt10">
	<div class="login mt10" style="border: none;">
			<table id="leaguelist" style="width:100%"></table>
			<div class="clear"></div>
		</div>
		<?php include $this->admin_tpl("copyright"); ?>
		<div class="clear"></div>
</div>
<script type="text/javascript">
	var dom = $('#leaguelist');
	var pageSize = <?php echo PAGE_SIZE?>;
	var dataurl = '<?php echo U('type')?>';
	var addurl = '<?php echo U('typeadd')?>';
	var editurl = '<?php echo U('typeadd',array('opt'=>'edit'))?>';
	var delurl = '<?php echo U('typeadd',array('opt'=>'del'))?>';
	$(function(){
		dom.datagrid({
			url:dataurl,
			striped:true,
			width:'100%',
			toolbar:[{
					id:'delrows',
					text:'删除',
					iconCls:'icon-del',
				},'-',
				{
					id:'addrow',
					text:'添加',
					iconCls:'icon-add',
				},'-'
			],
			frozenColumns:[[
				{field:'id',checkbox:true}
			]],
			checkOnSelect:true,
			singleSelect:true,
			fitColumns:true,
			pagination:true,
			pageSize:pageSize,
			pageList: [pageSize,pageSize*2,pageSize*4],//可以设置每页记录条数的列表
			columns:[[
				{field:'type_name',title:'分类名称',width:'20%',align:'center'},
				{field:'none',title:'编辑',width:'10%',halign:'center',align:'center',
					formatter:function(value,row,index){
						var edithtml = '<a href="'+editurl+'&id='+row.id+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;';
						var delhtml = '<a onclick="dom.datagrid(\'clearSelections\').datagrid(\'clearChecked\').datagrid(\'checkRow\','+index+');$(\'#delrows\').trigger(\'click\')" href="#">删除</a>';
						return edithtml + delhtml;
					}
				},
			]],
		});
		
		$('#addrow').bind('click', function(){
			window.location.href=addurl;
		})
		$('#delrows').bind('click', function(){
		
			var ids = [];
			var rows = dom.datagrid('getSelections');
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].id);
			}
			if (ids.length > 0){
				$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
					if (r){
						$.getJSON(delurl,
						{"id[]":ids},
						function(data){
							if(1 == data.status){// 删除成功，则需要在树中删除节点
								// 检修任务grid 执行load
								dom.datagrid("reload");  //重新加载
							}else{
								$.messager.alert('警告',data.info);
							}
						})
					}else{
						dom.datagrid('clearSelections').datagrid('clearChecked');
					}
				});
			}else{
				$.messager.alert('警告','请选择要删除的记录');
				return false;
			}
		});
		
		
	});
	//添加
	//增加查询参数，重新加载表格
	$('#search').bind('click',function (){
		var queryParams = dom.datagrid('options').queryParams;
		//查询参数直接添加在queryParams中
		queryParams.province = $("#province").val();
		queryParams.city = $("#city").val();
		queryParams.district = $("#district").val();
		queryParams.keyword = $("#keyword").val();
		dom.datagrid('options').queryParams = queryParams;
		dom.datagrid('reload');
	})

	
</script>
